{extend name="public:base" /}
{block name="menu"}数据字段{/block}
{block name="table-head"}
<tr>
    <th>表名</th>
    <th>引擎</th>
    <th>字符集</th>
    <th>索引大小</th>
    <th>数据大小</th>
    <th>行数</th>
    <th>备注</th>
    <th>创建时间</th>
    <th>操作</th>
</tr>
{/block}
{block name="table-body"}
{if condition="!count($tables)"}
<tr>
    <td colspan="7" class="text-center">没有数据</td>
</tr>
{else/}
{foreach $tables as $key => $table}
<tr>
    <td>{$table['Name']}</td>
    <td>{$table['Engine']}</td>
    <td>{$table['Collation']}</td>
    {if condition="$table['Index_length'] < 1024 * 1024"}
        <td>{:round($table['Index_length']/1024, 2)} KB</td>
    {else/}
        <td>{round($table['Index_length']/1024/1024, 2)} MB</td>
    {/if}
    {if condition="$table['Data_length'] < 1024 * 1024"}
        <td>{:round($table['Data_length']/1024, 2)} KB</td>
    {else/}
        <td>{round($table['Data_length']/1024/1024, 2)} MB</td>
    {/if}
    <td>{$table['Rows']}</td>
    <td>{$table['Comment']}</td>
    <td>{$table['Create_time']}</td>
    <td>
        <button class="btn btn-info btn-xs" type="button" data="{$table['Name']}" onclick="optimize($(this).attr('data'));"><i class="fa fa-paper-plane-o"></i> 优化</button>
        <button class="btn btn-primary btn-xs" type="button" data="{:url('database/view', ['table' => $table['Name']])}" onclick="view($(this).attr('data'));"><i class="fa fa-eye"></i> 查看</button>
    </td>
</tr>
{/foreach}
{/if}
{/block}
{block name="js"}
<script>
        // 优化
        function optimize(table) {
            $.post("{:url('database/optimize')}", {table: table}, function (response) {
                    if (!response.code) {
                        error(response.msg);
                    } else {
                        success(response.msg);
                    }
            })
        }
        // 查看数据表结构
        function view(url) {
                layer.open({
                    type: 2,
                    title: '数据表结构',
                    closeBtn: 1, //不显示关闭按钮
                    area: ['800px', '600px'],
                    content: url, //iframe的url，no代表不显示滚动条
                });
        }
</script>
{/block}
